/* See LICENSE file for copyright and license details. */
#include <errno.h>
#include <fcntl.h>
#include <pwd.h>
#include <shadow.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include <sys/utsname.h>
#include <sys/ioctl.h>
#include <grp.h>
int main()
{
__uid_t uid = getuid();//you can change this to be the uid that you want

struct passwd* pw = getpwuid(uid);
if(pw == NULL){
    perror("getpwuid error: ");
}

int ngroups = 0;

//this call is just to get the correct ngroups
getgrouplist(pw->pw_name, pw->pw_gid, NULL, &ngroups);
__gid_t groups[ngroups];

//here we actually get the groups  . 
getgrouplist(pw->pw_name, pw->pw_gid, groups, &ngroups);


//example to print the groups name
for (int i = 0; i < ngroups; i++){
    struct group* gr = getgrgid(groups[i]);
    if(gr == NULL){
        perror("getgrgid error: ");
    }
if (strcmp("kc",gr->gr_name)  == 0 ){
printf("hi");	
}

}
}		
